 #-*-coding:utf-8-*-
class codearray:
    def GenerateList(self,initvalue,flg):
        '''
        Generate the List.
        '''
       
        f = lambda x: (2.0 * x) / (1.0 - x ** 2)
        g = lambda y: ((complex(0,y) ** 2 + 1.0) / (2.0 * complex(0,y))).imag
        #flag = 0
        outlist = list()
        while True:
            '''
                if flag % 2 == 0:
                    initvalue = g(f(initvalue))
                else:
                    initvalue = f(g(initvalue))
                       
                flag += 1
            '''
            initvalue = 2.0 * initvalue / (1.0 - initvalue ** 2)            
            if flg:
                if initvalue >= 1:
                    k = 1
                elif initvalue < 1 and initvalue > 0:
                    k = 0
                elif initvalue > -1 and initvalue <= 0:
                    k = 1
                else:
                    k = 0
                yield k
            else:
                yield initvalue
            
    def GenerateBits(self,initvalue,lent,flg,pathname):
        fid = self.GenerateList(initvalue,flg)
        k = str(initvalue)
        for i in range(lent):
            k += str(fid.next())
            if not flg:
                k += ' '
        avf = open(pathname,'wb')
        avf.write(k)
        avf.flush()
        avf.close()
